package com.ls.dbpool;

import java.io.File;
import java.util.Iterator;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class PropertiesReader {
	private static Logger logger = Logger.getLogger(PropertiesReader.class);
	public Properties getProperties(String xmlFile) {
		Properties p = new Properties();
		try{
		 SAXReader reader=new SAXReader();
		 File f = new File(xmlFile);
		 Document document=reader.read(f);     
		 Element element=document.getRootElement();  
		 Element ele =  element.element("dataSource");
		 for (Iterator iter = ele.elementIterator(); iter.hasNext();)
	        {
	            Element e = (Element) iter.next();
	            p.put(e.getName(),String.valueOf(e.getData()));
	        }
		}catch(Exception e){
			logger.error("failed read xml file "+xmlFile,e);
		}
		return p;
	}
	public static void main(String[] args) {
		System.out.println(new PropertiesReader().getProperties("d:\\temp\\test.xml"));
	}
}
